package com.finance;

import com.finance.service.FinanceDataSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author sunyantao
 */
@Component
@Slf4j
public class AutoProcess implements CommandLineRunner {

    @Autowired
    FinanceDataSyncService financeDataSyncService;

    @Override
    public void run(String... args) {
        long start = System.currentTimeMillis();
        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 定义开始日期和结束日期变量
        LocalDate startDate = LocalDate.of(2025, 2, 1);
        LocalDate endDate = LocalDate.of(2025, 2, 3);

        // 循环处理日期范围内的每一天
        for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            String searchDate = date.format(formatter);
            financeDataSyncService.syncDataByDate(searchDate, true);
        }
        log.info("执行完成,总耗时:{}", System.currentTimeMillis() - start);
    }
}